package com.compass.doctor.dialog


import android.view.Gravity
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.FragmentActivity
import com.compass.doctor.databinding.DialogCodeBinding
import com.compass.doctor.utils.QRCodeDealUtils
import com.compass.framework.base.BaseDialog
import com.compass.framework.base.BaseDialogFragment
import com.compass.framework.ext.dp2px
import com.compass.framework.utils.LogUtil


/**
 * Description： 二维码弹窗
 * Date:2024/6/6 14:22
 */
class CodeDialog {

    class Builder(activity: FragmentActivity, private var codeUrl: String?) :
        BaseDialogFragment.Builder<Builder>(activity) {


        private val mBinding: DialogCodeBinding =
            DialogCodeBinding.inflate(LayoutInflater.from(activity))

        init {
            initView()
        }

        private fun initView() {

            setContentView(mBinding.root)
            setWidth(ViewGroup.LayoutParams.WRAP_CONTENT)
            setHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
            setAnimStyle(BaseDialog.AnimStyle.DEFAULT)
            setGravity(Gravity.CENTER)
            setCancelable(true)

            codeUrl?.let {
                LogUtil.e("codeUrl===$codeUrl")
                mBinding.imgWxCode.setImageBitmap(
                    QRCodeDealUtils.generateQRCodeWithoutMarginBlack(
                        it,
                        dp2px(400f),
                        dp2px(400f)
                    )
                )

            }


        }

        fun dismissDialog() {

            dismiss()
        }


    }
}